#include <iostream>
#include <vector>
#include <unistd.h>
#include <pthread.h>
#include "Thread.hpp"

using namespace ThreadMoudle;

int tickets = 10000;
void Routine(const std::string name)
{
    usleep(1000);
    while (true)
    {
        if (tickets > 0)
            std::cout << "get a tickets " << tickets-- << std::endl;
        else
            break;
    }
}

int num = 10;
int main()
{
    std::vector<Thread> threads;
    for (int i = 0; i < num; i++)
    {
        std::string name = " thread " + std::to_string(i + 1);
        threads.emplace_back(name, Routine);
    }
    for (auto &thread : threads)
        thread.Start();

    for (auto &thread : threads)
        thread.Join();
}

// const int gnum = 10;
// void Print(const std::string name)
// {
//     while (true)
//     {
//         std::cout << name <<"   is runing   "<< std::endl;
//         sleep(1);
//     }
// }
// 控制原生线程库
// int main()
// {
//     // 构建线程对象
//     std::vector<Thread> threads;
//     for (int i = 0; i < gnum; i++)
//     {
//         std::string name = "thread   " + std::to_string(i + 1);
//         threads.emplace_back(name, Print);
//         std::cout<<"thread "<<std::to_string(i+1)<< "  create"<<std::endl;
//     }

//     for (auto &thread : threads)
//         thread.Start();

//     sleep(3);

//     for(auto &thread:threads)
//     thread.Stop();

//     for(auto &thread:threads)
//     thread.Join();

//     return 0;
// }
